package com.ruoyi.steel_supplier_zlw.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.steel_supplier_zlw.domain.ZlwSteelSupplier;
import com.ruoyi.steel_supplier_zlw.service.IZlwSteelSupplierService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 钢材与供应商关系Controller
 * 
 * @author zlw
 * @date 2025-06-15
 */
@Controller
@RequestMapping("/steel_supplier_zlw/steel_supplier_zlw")
public class ZlwSteelSupplierController extends BaseController
{
    private String prefix = "steel_supplier_zlw/steel_supplier_zlw";

    @Autowired
    private IZlwSteelSupplierService zlwSteelSupplierService;

    @RequiresPermissions("steel_supplier_zlw:steel_supplier_zlw:view")
    @GetMapping()
    public String steel_supplier_zlw()
    {
        return prefix + "/steel_supplier_zlw";
    }

    /**
     * 查询钢材与供应商关系列表
     */
    @RequiresPermissions("steel_supplier_zlw:steel_supplier_zlw:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZlwSteelSupplier zlwSteelSupplier)
    {
        startPage();
        List<ZlwSteelSupplier> list = zlwSteelSupplierService.selectZlwSteelSupplierList(zlwSteelSupplier);
        return getDataTable(list);
    }

    /**
     * 导出钢材与供应商关系列表
     */
    @RequiresPermissions("steel_supplier_zlw:steel_supplier_zlw:export")
    @Log(title = "钢材与供应商关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZlwSteelSupplier zlwSteelSupplier)
    {
        List<ZlwSteelSupplier> list = zlwSteelSupplierService.selectZlwSteelSupplierList(zlwSteelSupplier);
        ExcelUtil<ZlwSteelSupplier> util = new ExcelUtil<ZlwSteelSupplier>(ZlwSteelSupplier.class);
        return util.exportExcel(list, "钢材与供应商关系数据");
    }

    /**
     * 新增钢材与供应商关系
     */
    @RequiresPermissions("steel_supplier_zlw:steel_supplier_zlw:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存钢材与供应商关系
     */
    @RequiresPermissions("steel_supplier_zlw:steel_supplier_zlw:add")
    @Log(title = "钢材与供应商关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZlwSteelSupplier zlwSteelSupplier)
    {
        return toAjax(zlwSteelSupplierService.insertZlwSteelSupplier(zlwSteelSupplier));
    }

    /**
     * 修改钢材与供应商关系
     */
    @RequiresPermissions("steel_supplier_zlw:steel_supplier_zlw:edit")
    @GetMapping("/edit/{steelId}")
    public String edit(@PathVariable("steelId") String steelId, ModelMap mmap)
    {
        ZlwSteelSupplier zlwSteelSupplier = zlwSteelSupplierService.selectZlwSteelSupplierBySteelId(steelId);
        mmap.put("zlwSteelSupplier", zlwSteelSupplier);
        return prefix + "/edit";
    }

    /**
     * 修改保存钢材与供应商关系
     */
    @RequiresPermissions("steel_supplier_zlw:steel_supplier_zlw:edit")
    @Log(title = "钢材与供应商关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZlwSteelSupplier zlwSteelSupplier)
    {
        return toAjax(zlwSteelSupplierService.updateZlwSteelSupplier(zlwSteelSupplier));
    }

    /**
     * 删除钢材与供应商关系
     */
    @RequiresPermissions("steel_supplier_zlw:steel_supplier_zlw:remove")
    @Log(title = "钢材与供应商关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zlwSteelSupplierService.deleteZlwSteelSupplierBySteelIds(ids));
    }
}
